using Youz.Common.DBUtility;
using Youz.CreditRepay.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.CreditRepay.DAL
{
    /// <summary>
    /// Pay_PayEaseResultsDAL Data Class
    /// </summary>
    public partial class Pay_PayEaseResultsDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Pay_PayEaseResults";

        public Pay_PayEaseResultsDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Pay_PayEaseResults model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Pay_PayEaseResults](");
            strSql.Append("[PaymentResultsID],[v_oid],[v_pmode],[v_pstatus],[v_pstring],[v_md5info],[v_amount],[v_moneytype],[v_md5money],[v_sign],[md5info],[md5money],[Status],[CreateTime],[Memo],[v_count],[v_mac],[Type]");
            strSql.Append(") values (");
            strSql.Append("@PaymentResultsID,@v_oid,@v_pmode,@v_pstatus,@v_pstring,@v_md5info,@v_amount,@v_moneytype,@v_md5money,@v_sign,@md5info,@md5money,@Status,@CreateTime,@Memo,@v_count,@v_mac,@Type");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@PaymentResultsID", model.PaymentResultsID),
                    new SqlParameter("@v_oid", model.v_oid),
                    new SqlParameter("@v_pmode", model.v_pmode),
                    new SqlParameter("@v_pstatus", model.v_pstatus),
                    new SqlParameter("@v_pstring", model.v_pstring),
                    new SqlParameter("@v_md5info", model.v_md5info),
                    new SqlParameter("@v_amount", model.v_amount),
                    new SqlParameter("@v_moneytype", model.v_moneytype),
                    new SqlParameter("@v_md5money", model.v_md5money),
                    new SqlParameter("@v_sign", model.v_sign),
                    new SqlParameter("@md5info", model.md5info),
                    new SqlParameter("@md5money", model.md5money),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@Memo", model.Memo),
                    new SqlParameter("@v_count",model.v_count),
                    new SqlParameter("@v_mac",model.v_mac),
                    new SqlParameter("@Type",model.Type)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Pay_PayEaseResults model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Pay_PayEaseResults] set ");
            strSql.Append("[v_oid]=@v_oid,[v_pmode]=@v_pmode,[v_pstatus]=@v_pstatus,[v_pstring]=@v_pstring,[v_md5info]=@v_md5info,[v_amount]=@v_amount,[v_moneytype]=@v_moneytype,[v_md5money]=@v_md5money,[v_sign]=@v_sign,[md5info]=@md5info,[md5money]=@md5money,[Status]=@Status,[CreateTime]=@CreateTime,[Memo]=@Memo,[v_count]=@v_count,[v_mac]=@v_mac");
            strSql.Append(" where [PaymentResultsID]=@PaymentResultsID");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@PaymentResultsID", model.PaymentResultsID),
                    new SqlParameter("@v_oid", model.v_oid),
                    new SqlParameter("@v_pmode", model.v_pmode),
                    new SqlParameter("@v_pstatus", model.v_pstatus),
                    new SqlParameter("@v_pstring", model.v_pstring),
                    new SqlParameter("@v_md5info", model.v_md5info),
                    new SqlParameter("@v_amount", model.v_amount),
                    new SqlParameter("@v_moneytype", model.v_moneytype),
                    new SqlParameter("@v_md5money", model.v_md5money),
                    new SqlParameter("@v_sign", model.v_sign),
                    new SqlParameter("@md5info", model.md5info),
                    new SqlParameter("@md5money", model.md5money),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@Memo", model.Memo),
                    new SqlParameter("@v_count",model.v_count),
                    new SqlParameter("@v_mac",model.v_mac)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid PaymentResultsID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Pay_PayEaseResults] ");
            strSql.Append(" where [PaymentResultsID]=@PaymentResultsID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@PaymentResultsID", PaymentResultsID)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pay_PayEaseResults Get(Guid PaymentResultsID)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Pay_PayEaseResults] ");
            strSql.Append(" where [PaymentResultsID]=@PaymentResultsID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("PaymentResultsID", PaymentResultsID)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pay_PayEaseResults Get(DataRow row)
        {
            if (row == null) return null;

            Pay_PayEaseResults model = new Pay_PayEaseResults();
	
            
            if (row["PaymentResultsID"] != DBNull.Value)
            {
                model.PaymentResultsID = (Guid)row["PaymentResultsID"];
            }      
            
            if (row["v_oid"] != DBNull.Value)
            {
                model.v_oid = (String)row["v_oid"];
            }      
            
            if (row["v_pmode"] != DBNull.Value)
            {
                model.v_pmode = (String)row["v_pmode"];
            }      
            
            if (row["v_pstatus"] != DBNull.Value)
            {
                model.v_pstatus = (String)row["v_pstatus"];
            }      
            
            if (row["v_pstring"] != DBNull.Value)
            {
                model.v_pstring = (String)row["v_pstring"];
            }      
            
            if (row["v_md5info"] != DBNull.Value)
            {
                model.v_md5info = (String)row["v_md5info"];
            }      
            
            if (row["v_amount"] != DBNull.Value)
            {
                model.v_amount = (String)row["v_amount"];
            }      
            
            if (row["v_moneytype"] != DBNull.Value)
            {
                model.v_moneytype = (String)row["v_moneytype"];
            }      
            
            if (row["v_md5money"] != DBNull.Value)
            {
                model.v_md5money = (String)row["v_md5money"];
            }      
            
            if (row["v_sign"] != DBNull.Value)
            {
                model.v_sign = (String)row["v_sign"];
            }      
            
            if (row["md5info"] != DBNull.Value)
            {
                model.md5info = (String)row["md5info"];
            }      
            
            if (row["md5money"] != DBNull.Value)
            {
                model.md5money = (String)row["md5money"];
            }      
            
            if (row["Status"] != DBNull.Value)
            {
                model.Status = (Int32)row["Status"];
            }      
            
            if (row["CreateTime"] != DBNull.Value)
            {
                model.CreateTime = (DateTime)row["CreateTime"];
            }      
            
            if (row["Memo"] != DBNull.Value)
            {
                model.Memo = (String)row["Memo"];
            }
            if (row["v_count"] != DBNull.Value)
            {
                model.v_count = (String)row["v_count"];
            }
            if (row["v_mac"] != DBNull.Value)
            {
                model.v_mac = (String)row["v_mac"];
            }

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Pay_PayEaseResults] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Pay_PayEaseResults] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Pay_PayEaseResults] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Pay_PayEaseResults]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by CreateTime desc ", out count, cmdParms);
            total = count;
            return dt;
        }

        
      #endregion  成员方法
    }
}


  